package com.jy.adscm.operation.hr.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.hr.bean.HrResume;
import com.jy.adscm.operation.hr.service.HrResumeService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 人力资源简历 前端控制器
 * </p>
 *
 * @author zyl
 * @since 2020-01-07
 */
@RestController
@RequestMapping("/adscm/operation/hrResume")
public class HrResumeController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    HrResumeService hrResumeService;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody HrResume hrResume, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        hrResume.setCreator(token.getUser().getId().toString());
        hrResume.setCreateTime(new Date());
        boolean insert = hrResumeService.insertHrResume(hrResume);
        return new SimpleCoreResponse("200","新增成功",insert);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody HrResume hrResume, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        hrResume.setCreator(token.getUser().getId().toString());
        hrResume.setCreateTime(new Date());
        boolean insert = hrResumeService.updateHrResume(hrResume);
        return new SimpleCoreResponse("200","修改成功",insert);
    }
    @RequestMapping("selectByHid/{hid}")
    public SimpleCoreResponse selectByHid(@PathVariable Integer hid, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<HrResume> hrResumes = hrResumeService.selectByHid(hid);
        return new SimpleCoreResponse("200","修改成功",hrResumes);
    }


}

